package com.up.upzl.base.domain;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;

import lombok.Getter;
import lombok.Setter;

/**
 * 实体基类
 * 
 * @author geeks
 *
 */
@Getter
@Setter
@MappedSuperclass
public class BaseDomain implements Serializable {

	private static final long serialVersionUID = 1359052286325363912L;

	/**
	 * 主键
	 */
	@Id
	@GeneratedValue
	private Long id;

	/**
	 * 创建时间
	 */
	@Column(updatable = false)
	private Date createTime;

	/**
	 * 更新时间
	 */
	private Date updateTime;

	/**
	 * 创建时间
	 */
	@PrePersist
	public void setCreateTime() {
		Date date = new Date();
		createTime = date;
		updateTime = date;
	}

	/**
	 * 更新时间
	 */
	@PreUpdate
	public void setUpdateTime() {
		this.updateTime = new Date();
	}
}
